﻿using Microsoft.AspNetCore.Http;

using System;

namespace Utils
{
    public class SecurityCall
    {
        public static Model.Result<T> SafeCall<T>(Func<Model.Result<T>> func)
        {
            try
            {
                return func();
            }
            catch (Exception e)
            {
                return new Model.Result<T>()
                {
                    Code = 500,
                    Data = default,
                    Message = "发生未知错误",
                };
                throw e;
            }
        }

        //public static void SafeCall(Func<Model.Basic.ResultPageModel> func)
        //{
        //    try
        //    {
        //        var context = HttpContextClass.ServiceProvider.GetRequiredService<IHttpContextAccessor>().HttpContext;
        //        context.Items["result"] = func();
        //    }
        //    catch (Exception e)
        //    {
        //        Console.WriteLine(e.Message);
        //        throw;
        //    }
        //}
    }
}
